package com.ruoyi.guidance.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.guidance.domain.JwStuCompetitionGuidance;
import com.ruoyi.guidance.service.IJwStuCompetitionGuidanceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学科竞赛指导Controller
 * 
 * @author ruoyi
 * @date 2024-11-13
 */
@RestController
@RequestMapping("/guidance/guidance")
public class JwStuCompetitionGuidanceController extends BaseController
{
    @Autowired
    private IJwStuCompetitionGuidanceService jwStuCompetitionGuidanceService;

    /**
     * 查询学科竞赛指导列表
     */
    @PreAuthorize("@ss.hasPermi('guidance:guidance:list')")
    @GetMapping("/list")
    public TableDataInfo list(JwStuCompetitionGuidance jwStuCompetitionGuidance)
    {
        startPage();
        List<JwStuCompetitionGuidance> list = jwStuCompetitionGuidanceService.selectJwStuCompetitionGuidanceList(jwStuCompetitionGuidance);
        return getDataTable(list);
    }

    /**
     * 导出学科竞赛指导列表
     */
    @PreAuthorize("@ss.hasPermi('guidance:guidance:export')")
    @Log(title = "学科竞赛指导", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JwStuCompetitionGuidance jwStuCompetitionGuidance)
    {
        List<JwStuCompetitionGuidance> list = jwStuCompetitionGuidanceService.selectJwStuCompetitionGuidanceList(jwStuCompetitionGuidance);
        ExcelUtil<JwStuCompetitionGuidance> util = new ExcelUtil<JwStuCompetitionGuidance>(JwStuCompetitionGuidance.class);
        util.exportExcel(response, list, "学科竞赛指导数据");
    }

    /**
     * 获取学科竞赛指导详细信息
     */
    @PreAuthorize("@ss.hasPermi('guidance:guidance:query')")
    @GetMapping(value = "/{scgId}")
    public AjaxResult getInfo(@PathVariable("scgId") Long scgId)
    {
        return success(jwStuCompetitionGuidanceService.selectJwStuCompetitionGuidanceByScgId(scgId));
    }

    /**
     * 新增学科竞赛指导
     */
    @PreAuthorize("@ss.hasPermi('guidance:guidance:add')")
    @Log(title = "学科竞赛指导", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JwStuCompetitionGuidance jwStuCompetitionGuidance)
    {
        SysUser user= SecurityUtils.getLoginUser().getUser();
        jwStuCompetitionGuidance.setDeptId(104L);
        jwStuCompetitionGuidance.setUserId(user.getUserId());
        return toAjax(jwStuCompetitionGuidanceService.insertJwStuCompetitionGuidance(jwStuCompetitionGuidance));
    }

    /**
     * 修改学科竞赛指导
     */
    @PreAuthorize("@ss.hasPermi('guidance:guidance:edit')")
    @Log(title = "学科竞赛指导", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JwStuCompetitionGuidance jwStuCompetitionGuidance)
    {
        return toAjax(jwStuCompetitionGuidanceService.updateJwStuCompetitionGuidance(jwStuCompetitionGuidance));
    }

    /**
     * 删除学科竞赛指导
     */
    @PreAuthorize("@ss.hasPermi('guidance:guidance:remove')")
    @Log(title = "学科竞赛指导", businessType = BusinessType.DELETE)
	@DeleteMapping("/{scgIds}")
    public AjaxResult remove(@PathVariable Long[] scgIds)
    {
        return toAjax(jwStuCompetitionGuidanceService.deleteJwStuCompetitionGuidanceByScgIds(scgIds));
    }
}
